import java.io.*;
import java.util.*;

class Read {
    StringTokenizer st=new StringTokenizer("");
    BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
    public String next() throws IOException {
        while (!st.hasMoreTokens()){
            st=new StringTokenizer(bf.readLine());
        }
        return st.nextToken();
    }
    public String nextLine() throws IOException {
            return bf.readLine();
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    public Double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }
    public float nextFloat() throws IOException {
        return Float.parseFloat(next());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(next());
    }

}
public class Main {
    public static Read in=new Read();
    public static PrintWriter out= new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static void main1(String[] args) throws IOException {
        int n= in.nextInt(),power= in.nextInt();
        int ret=power;
        int[] p=new int[n];
        for (int i = 0; i < n; i++) {
            p[i]= in.nextInt();
            if(power>=p[i]){
                power+=p[i];
            }
            else {
               int num=power,j=p[i];
               while (num!=j){
                   if(num>j) num-=j;
                   else j-=num;
               }
               power+=num;
            }
        }
        out.println(power);
        out.close();
    }

    public static void main2(String[] args) {
        Scanner in=new Scanner(System.in);
        int t= in.nextInt();
        while (t-->0){
            int n= in.nextInt();
            if(n==1) {
                char[] s=in.next().toCharArray();
            }
            else {
                String[] arr=new String[n];
                Map<Character,Integer> hash=new HashMap<>();
                for (int i = 0; i < n; i++) {
                   arr[i]=in.next();
                   hash.put(arr[i].charAt(0),hash.getOrDefault(hash.get(arr[i].charAt(0)),0)+1);
                }
                int ret=0;
                for(int v:hash.values()){
                    if(v%2!=0) ret++;
                }
                if(n%2==0&&ret==0) System.out.println("Yes");
                else if (n%2!=0&&ret==1) {
                    System.out.println("Yes");
                }
                else System.out.println("No");
            }
        }
    }
    public static boolean check(boolean[][] hash,int left,int right){
        for (int i = 0; i < 26; i++) {
            if(hash[left][i]&&hash[right][i]) return true;
        }
        return false;
    }
    public static void main3(String[] args) {
        Scanner in=new Scanner(System.in);
        int t= in.nextInt();
        while (t-->0){
            int n= in.nextInt();
            if(n==1){
                String s= in.next();
                System.out.println("Yes");
            }
            else {
                boolean[][] hash=new boolean[n][26];
                for (int i = 0; i < n; i++) {
                    String str= in.next();
                    char[] arr=str.toCharArray();
                    for (int j = 0; j < arr.length; j++) {
                        hash[i][arr[j]-'a']=true;
                    }
                }
                int left=0,right=n-1;
                while (left<right){
                    if(!check(hash,left,right)) break;
                    left++;
                    right--;
                }
                if(left<right) System.out.println("No");
                else System.out.println("Yes");
            }
        }
    }
    public int maxValue (int[][] grid) {
        int n= grid.length,m=grid[0].length;
        int[][] dp=new int[n+1][m+1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1])+grid[i-1][j-1];
            }
        }
        return dp[n][m];
    }

    public static void main4(String[] args) throws IOException {
       int a= in.nextInt(),h= in.nextInt(),b= in.nextInt(),k= in.nextInt();
       int ret=0;
       while (h>=0&&k>=0) {
           ret+=a+b;
           h-=b;
           k-=a;
       }
       if(h<=0&&k>0) ret=ret+b*10;
       else if (h>0&&k<=0) {
           ret=ret+a*10;
       }
        System.out.println(ret);
    }

    public static void main5(String[] args) throws IOException {
        int n=in.nextInt();
        int[] nums=new int[n];
        for (int i = 0; i < n; i++) {
            nums[i]= in.nextInt();
        }
        int[] dp=new int[n+1];
        int max=Integer.MIN_VALUE;
        for (int i = 1; i <= n; i++) {
            dp[i]=Math.max(dp[i-1]+nums[i-1],nums[i-1]);
            max=Math.max(dp[i],max);
        }
        System.out.println(max);
    }

    public static void main6(String[] args) throws IOException {
        String str=in.next();
        char[] arr=str.toCharArray();
        int n=arr.length;
        boolean flag = false;
        for (int i = 1; i < n; i++) {
            if(arr[i]!=arr[i-1]) {
                flag=true;
                break;
            }
        }
        if(!flag) System.out.println(0);
        else {
            int left=0,right=n-1;
            while (left<right) {
                if(arr[left]==arr[right]){
                    right--;
                    left++;
                }
                else {
                    flag=false;
                    break;
                }
            }
            if(flag) System.out.println(n-1);
            else System.out.println(n);
        }
    }

    public static void main7(String[] args) throws IOException {
        int n= in.nextInt();
        int[] nums=new int[n];
        for (int i = 0; i < n; i++) {
            nums[i]=i+1;
        }
        for (int i = 1; i < n-1; i++) {
            if(nums[i]>nums[i-1]&&nums[i]<nums[i+1]){
                int s=nums[i];
                nums[i]=nums[i+1];
                nums[i+1]=s;
            }
        }
        for (int i = 0; i < n; i++) {
            System.out.println(nums[i]+" ");
        }
    }

    public static void main8(String[] args) throws IOException {
        Set<Integer> hash=new HashSet<>();
        int n= in.nextInt(),m= in.nextInt();
        int[] nums1=new int[n],nums2=new int[m];
        for (int i = 0; i < n; i++) {
            nums1[i]= in.nextInt();
        }
        for (int i = 0; i < m; i++) {
            nums2[i]= in.nextInt();
        }
        int i=0,k=0;
        while (i<n&&k<m) {
            if(nums1[i]<nums2[k]){
                hash.add(nums1[i++]);
            }
            else hash.add(nums2[k++]);
        }
        if(i<n){
            while (i<n) hash.add(nums1[i++]);
        }
        if(k<m){
            while (k<m) hash.add(nums2[k++]);
        }
        hash.stream().forEach(element->{
            System.out.print(" "+element);
        });
    }

    public static void main9(String[] args) throws IOException {
        String str= in.next();
        char[] arr=str.toCharArray();
        int n=arr.length;
        int[][] dp=new int[n][n];
        for (int i = n-1; i >= 0; i--) {
            dp[i][i]=1;
            for (int j = i+1; j < n; j++) {
               if(arr[i]==arr[j]) dp[i][j]=dp[i+1][j-1]+2;
               else dp[i][j]=Math.max(dp[i][j-1],dp[i+1][j]);
            }
        }
        System.out.println(dp[0][n - 1]);
    }

    public static void main10(String[] args) throws IOException {
        String A= in.next();
        String B= in.next();
        int ret=0;
        if(A.length()==B.length()) {
            for (int i = 0; i < A.length(); i++) {
                if(A.charAt(i)!=B.charAt(i)) {
                    ret++;
                }
            }
        }
        else {
            int max=100;
            for (int i = 0; i <= B.length()-A.length(); i++) {
                int k=i;
                for (int j = 0; j < A.length(); j++) {
                    if(A.charAt(j)!=B.charAt(k)) ret++;
                    k++;
                }
                max=Math.min(max,ret);
                ret=0;
            }
            System.out.println(max);
        }
    }

    public static void main11(String[] args) throws IOException {
        int n= in.nextInt();
        long[] nums=new long[n];
        long max=0;
        for (int i = 0; i < n; i++) {
            nums[i]=in.nextLong();
            if(nums[i]>max) max=nums[i];
        }
        boolean flag=true;
        for (int i = 0; i < n; i++) {
            if(max%nums[i]==0){
                if((nums[i]&(nums[i]-1))!=0) {
                    flag=false;
                    break;
                }
            }
            else {
                flag=false;
                break;
            }
        }
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }

    public static void main12(String[] args) throws IOException {
        int V= in.nextInt(),n= in.nextInt();
        int[] nums=new int[n+1];
        for (int i = 1; i <= n; i++) {
            nums[i]=in.nextInt();
        }
        int[] dp=new int[V+1];
        for (int i = 1; i < n; i++) {
            for (int j = V; j >= nums[i]; j--) {
               dp[j]=Math.max(dp[j],dp[j-nums[i]]+nums[i]);
            }
        }
        System.out.println(V-dp[V]);
    }

    public static void main13(String[] args) throws IOException {
        int t= in.nextInt();
        while (t-->0){
            int blood= in.nextInt(),power= in.nextInt();
            int blood2= in.nextInt(),power2= in.nextInt();
            if(power>=blood2) System.out.println(-1);
            else {
                int m=blood2/power+(blood2%power==0?0:1);
                int n=m-1;
                int x=power2*n;
                int ret=blood/x-(blood%x==0?1:0);
                System.out.println(ret);
            }
        }
    }

    public static void main14(String[] args) throws IOException {
        int n= in.nextInt();
        HashSet<String> hash=new HashSet<>();
        while (n-->0){
            String s= in.next();
            char[] arr=s.toCharArray();
            Arrays.sort(arr);
            hash.add(new String(arr));
        }
        System.out.println(hash.size());
    }
    int n;
    boolean[] vis=new boolean[210];
    public int citys (ArrayList<ArrayList<Integer>> m) {
        int n=m.size();
        int ret=0;
        for(int i=0;i<n;i++){
            if(vis[i]==false){
                ret+=1;
                dfs(m,i);
            }
        }
        return ret;
    }
    public void dfs(ArrayList<ArrayList<Integer>> m,int pos){
        vis[pos]=true;
        for(int i=0;i<n;i++){
            if(m.get(pos).get(i)==1&&vis[i]==false){
                dfs(m,i);
            }
        }
    }
    public int maxSubarraySumCircular(int[] nums) {
        int n=nums.length;
        int[] f=new int[n+1];
        int[] g=new int[n+1];
        int fMax=Integer.MIN_VALUE,gMin=Integer.MAX_VALUE;
        int sum=0;
        for(int i=1;i<=n;i++){
            int x=nums[i-1];
            f[i]=Math.max(x,f[i-1]+x);
            fMax=Math.max(fMax,f[i]);
            g[i]=Math.min(x,g[i-1]+x);
            gMin=Math.min(gMin,g[i]);
            sum+=x;
        }
        return gMin==sum?fMax:Math.max(fMax,sum-gMin);
    }
    public class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;
    public TreeNode(int val) {
      this.val = val;
    }
  }
    public boolean IsBalanced_Solution (TreeNode pRoot) {
        if(pRoot==null) return true;
        if(Math.abs(dfs2(pRoot.left)-dfs2(pRoot.right))<=1) return true;
        return false;
    }

    private static int dfs2(TreeNode root) {
        if(root==null) return 0;
        return 1+Math.max(dfs2(root.left),dfs2(root.right));
    }

    public static void main15(String[] args) throws IOException {
        int n= in.nextInt();
        int[][] nums=new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                nums[i][j]= in.nextInt();
            }
        }
        int [][] dp=new int[n+1][n+1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+nums[i-1][j-1];
            }
        }
        int ret=-127;
        for (int x1 = 1; x1 <= n; x1++) {
            for (int y1 = 1; y1 <= n; y1++) {
                for (int x2 = x1; x2 <= n; x2++) {
                    for (int y2 = y1; y2 <= n; y2++) {
                        ret=Math.max(ret,dp[x2][y2]-dp[x2][y1-1]-dp[x1-1][y2]+dp[x1-1][y1-1]);
                    }
                }
            }
        }
        System.out.println(ret);
    }

    public static void main(String[] args) throws IOException {
        int n= in.nextInt();
        String s= in.next();
        char[] arr=s.toCharArray();
        int[] sum=new int[2];
        for (int i = 0; i < n; i++) {
            sum[arr[i]-'0']++;
        }
        int ret=0,left=0,right=0;
        int[] count=new int[2];
        while (right<n){
            count[arr[right]-'0']++;
            while (right-left+1>n/2) count[arr[left++]-'0']--;
            if(right-left+1==n/2){
                if(count[0]*2==sum[0]&&count[1]*2==sum[1]){
                    ret+=2;
                }
            }
            right++;
        }
        System.out.println(ret);
    }
}